package com.hptpd.questionnairesurvey.vo;

import com.google.common.collect.Lists;
import com.hptpd.questionnairesurvey.domain.Survey;
import com.hptpd.questionnairesurvey.domain.User;
import com.hptpd.questionnairesurvey.domain.UserSurvey;
import com.hptpd.questionnairesurvey.domain.UserSurveyResult;
import com.hptpd.questionnairesurvey.utils.AbstractMyBeanUtils;
import com.hptpd.questionnairesurvey.utils.DateUtil;
import lombok.Data;

import javax.persistence.Column;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import java.util.Date;
import java.util.List;

/**
 * \* Created with IntelliJ IDEA.
 * \* Date: 2019/11/11
 * \*
 * \* Description:
 * \
 *
 * @author walter_long
 */
@Data
public class UserSurveyVo {
    private String id;

    private Boolean isDone;

    private Date doneTime;

    private String doneTimeStr;

    private UserVo userVo;

    private SurveyVo surveyVo;

    private List<UserSurveyResultVo> userSurveyResultVos;

    public static List<UserSurveyVo> convertUserSurvey(List<UserSurvey> userSurveys) {
        List<UserSurveyVo> userSurveyVos = Lists.newLinkedList();
        for (UserSurvey userSurvey : userSurveys) {
            userSurveyVos.add(convertUserSurvey(userSurvey));
        }
        return userSurveyVos;
    }

    public static UserSurveyVo convertUserSurvey(UserSurvey userSurvey) {
        if (null == userSurvey) {
            return null;
        }
        UserSurveyVo userSurveyVo = new UserSurveyVo();
        AbstractMyBeanUtils.copyProperties(userSurvey, userSurveyVo);
        userSurveyVo.setSurveyVo(SurveyVo.convertSurvey(userSurvey.getSurvey()));
        userSurveyVo.setUserSurveyResultVos(UserSurveyResultVo.convertUserSurveyResult(userSurvey.getUserSurveyResults()));
        if (null != userSurvey.getDoneTime()) {
            userSurveyVo.setDoneTimeStr(DateUtil.dateToString(userSurvey.getDoneTime()));
        }
        return userSurveyVo;
    }
}
